﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;

namespace ATEGo
{
    public partial class Input : Form
    {
        public Input()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 输入提示语
        /// </summary>
        public string Reminder 
        { 
            get
            {
                return label1.Text;
            }
            set 
            {
                label1.Text = value;
            }
        }

        /// <summary>
        /// 检测的正则
        /// </summary>
        public string CheckReg { get; set; } = "";

        /// <summary>
        /// 用户输入
        /// </summary>
        public string UserInput
        { 
            get
            {
                return textBox1.Text.Trim();
            }
        }

        /// <summary>
        /// 点击继续
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(UserInput))
            {
                var myinput = UserInput.Trim();
                if (!string.IsNullOrEmpty(CheckReg))
                {
                    //正则检验
                    CheckReg = CheckReg.Trim();
                    if (Regex.IsMatch(myinput, CheckReg.Replace("\\\\","\\")))
                    {
                        this.Close();
                        return;
                    }
                }
                else
                {
                    //无须检验
                    this.Close();
                    return;
                }
            }
            //验证失败
            textBox1.Text = "";
        }

        public void ShowDialog(IExecutorForm thisForm)
        {
            Action  t =  () =>
            {
                this.ShowDialog();
            };
            thisForm.Invoke(t);
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                button1_Click(this, null);
            }
        }

    }
}
